home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue30 / pathed3 / PATHED3.ZIP / Source / SolutionsUnlimitedPathEd.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-12-28  |  20.2 KB  |  770 lines

  1. {-------------------------------------------------------------------------------
  2. Name                    :    SolutionsUnlimitedPathEd.pas
  3. Author                : Robert Kozak
  4. Date                    : November 1, 1997
  5.  
  6. Copyright            : ⌐ 1997 Solutions Unlimited. All Rights Reserved.
  7.  
  8. Version             : 1.0
  9. Last Updated    :
  10.  
  11. Description        : This is an expert for managing the Paths in Delphi.
  12.  
  13. Notes:
  14. -------------------------------------------------------------------------------}
  15. unit SolutionsUnlimitedPathEd;
  16.  
  17. interface
  18.  
  19. uses
  20.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  21.   ComCtrls, Registry, StdCtrls, ExptIntf, ToolIntf, Placemnt,
  22.   ExtCtrls, rkCommon, Menus, checklst, SolutionsUnlimitedBrowseFolder, rkAboutForm;
  23.  
  24. const
  25.   DELPHI_3_PATHHISTORY        = '\Software\Borland\Delphi\3.0\HistoryList\hiLibraryPath';
  26.     DELPHI_3_PATH                             = '\Software\Borland\Delphi\3.0\Library\';
  27.     DELPHI_3_FULLPATH                        = '\Software\Borland\Delphi\3.0\Library\FULLPath\';
  28.     DELPHI_3_KNOWN_PACKAGES         = '\Software\Borland\Delphi\3.0\Known Packages';
  29.     DELPHI_3_DISABLED_PACKAGES    = '\Software\Borland\Delphi\3.0\Disabled Packages';
  30.  
  31.   DELPHI_3_SOLUTIONS                    = '\Software\Borland\Delphi\3.0\Solutions\';
  32.     DELPHI_3_PATH_KEY                        = 'SearchPath';
  33.  
  34. type
  35.   TPathEdExpert = class(TIExpert)
  36.   private
  37.     fMenuItem: TIMenuItemIntf;
  38.     procedure MenuClick(Sender: TIMenuItemIntf);
  39.     procedure NewWndProc(var Msg : TMessage); virtual;
  40.     protected
  41.         procedure PreProcessMsg(Sender: TObject; var msg: TMessage; var bContinue: Boolean);
  42.     procedure PostProcessMsg(Sender: TObject; var msg: TMessage; var bContinue: Boolean);
  43.         procedure UpdateDelphiPath;
  44.   public
  45.         constructor Create;
  46.     destructor Destroy; override;
  47.     procedure Execute; override;
  48.     function GetAuthor: string; override;
  49.     function GetComment: string; override;
  50.     function GetGlyph: HICON; override;
  51.     function GetIDString: string; override;
  52.     function GetMenuText: string; override;
  53.     function GetName: string; override;
  54.     function GetPage: string; override;
  55.     function GetState: TExpertState; override;
  56.     function GetStyle: TExpertStyle; override;
  57.     property MenuItem: TIMenuItemIntf read fMenuItem;
  58.   end;
  59.  
  60.   TfrmSetPath = class(TForm)
  61.     Panel1: TPanel;
  62.     btnDown: TButton;
  63.     btnAdd: TButton;
  64.     btnUp: TButton;
  65.     btnRemove: TButton;
  66.     StatusBar1: TStatusBar;
  67.     FormStorage: TFormStorage;
  68.     pnlList: TPanel;
  69.     TabControl1: TTabControl;
  70.     btnOptions: TButton;
  71.     PopupMenu1: TPopupMenu;
  72.     Sort1: TMenuItem;
  73.     btnClose: TButton;
  74.     lstPath: TCheckListBox;
  75.     N1: TMenuItem;
  76.     About1: TMenuItem;
  77.     procedure btnAddClick(Sender: TObject);
  78.     procedure btnRemoveClick(Sender: TObject);
  79.     procedure btnUpClick(Sender: TObject);
  80.     procedure btnDownClick(Sender: TObject);
  81.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  82.     procedure FormCreate(Sender: TObject);
  83.     procedure FormStorageRestorePlacement(Sender: TObject);
  84.     procedure btnOptionsClick(Sender: TObject);
  85.     procedure Sort1Click(Sender: TObject);
  86.     procedure About1Click(Sender: TObject);
  87.   private
  88.     { Private declarations }
  89.     FDisplayHistory : Boolean;
  90.     FDisplayPackagePath: Boolean;
  91.     FDisplayProject : Boolean;
  92.     FSyncPackages : Boolean;
  93.         OldList : TStringList;
  94.     PackagePath : TStringList;
  95.     procedure SaveList;
  96.     procedure RestoreList;
  97.     function ListSaved : Boolean;
  98.     procedure ParsePath;
  99.       procedure WritePath;
  100.       procedure ReadPath;
  101.     procedure SyncWithPackages;
  102.     procedure AddSubDirs(Sender: TObject);
  103.   protected
  104.     procedure SetDisplayPackagePath(Value : Boolean);
  105.     procedure SetSyncPackages(Value : Boolean);
  106.   public
  107.     { Public declarations }
  108.     property DisplayPackagePath: Boolean read FDisplayPackagePath write SetDisplayPackagePath;
  109.     property SyncPackages : Boolean read FSyncPackages write SetSyncPackages;
  110.   end;
  111.  
  112.     procedure Register;
  113.  
  114. var
  115.   frmSetPath: TfrmSetPath;
  116.     WindowHook : HHook;
  117.   DoSubClass : Boolean;
  118.     PathEdExpert : TPathEdExpert;
  119.   Path : string;
  120.  
  121. implementation
  122.  
  123. uses
  124.   SolutionsUnlimitedPathOptions;
  125.  
  126. resourcestring
  127.   sName = 'Library Search Path Expert';
  128.   sMenuText = 'Edit Library Search &Path...';
  129.   sMenuName = 'EditLibrarySearchPathItem';
  130.  
  131. {$R *.DFM}
  132.  
  133. var
  134.   NewWndProcPointer : TFarProc;
  135.   OrgWndProcPointer : LongInt;
  136.   WindowHandle : HWnd;
  137.  
  138. procedure TPathEdExpert.NewWndProc(var Msg : TMessage);
  139. //function NewWndProc(Handle : HWND; Msg : UInt; wparam : WPARAM; lparam: LPARAM): LRESULT; stdcall;
  140. var
  141.     EnvDialog : TCustomForm;
  142.   LibraryTab :  TTabSheet;
  143.  
  144.   PathCombo : TComboBox;
  145.   temp : string;
  146.  
  147. begin
  148.   case Msg.Msg of
  149.     WM_WINDOWPOSCHANGING :
  150.     begin
  151.         TWindowPos(pWindowPos(Msg.Lparam)^).cx := 0;
  152.         TWindowPos(pWindowPos(Msg.Lparam)^).cy := 0;
  153.       Msg.Result := 0;
  154.     end;
  155.  
  156.         CM_ACTIVATE:
  157.           if Application.FindComponent('EnvDialog') <> nil then
  158.         begin
  159.             EnvDialog := TForm(Application.FindComponent('EnvDialog'));
  160.           EnvDialog.ModalResult := mrOK;
  161.            PathCombo := TComboBox(EnvDialog.FindComponent('LibOptionsDlg2').FindComponent('ecLibraryPath'));
  162.         PathCombo.Text := Path;
  163.           PostMessage(EnvDialog.Handle, CM_DEACTIVATE, 0, 0);
  164.         Msg.Result := 0;
  165.         end;
  166.         CM_DEACTIVATE:
  167.           if Application.FindComponent('EnvDialog') <> nil then
  168.         begin
  169.           EnvDialog := TForm(Application.FindComponent('EnvDialog'));
  170.           EnvDialog.ModalResult := mrOK;
  171.         Msg.Result := 0;
  172.         end;          
  173.  
  174. //  else Result := CallWindowProc(Pointer(OrgWndProcPointer), Handle, Msg, wparam, lparam);
  175.   else Dispatch(Msg);
  176.   end;
  177. end;
  178.  
  179. {------------------------------------------------------------------------------}
  180.  
  181. function Hook(Code : Integer; wparam :WPARAM; lParam : LPARAM): LResult; stdcall;
  182. var
  183.     aClassName : array [0..25] of char;
  184.   i: integer;
  185.  
  186. begin
  187.     with TCWPStruct(PCWPStruct(lparam)^) do
  188.       if (Message = WM_ParentNotify) and (LoWord(wparam) = WM_CREATE) then
  189.         begin
  190.              WindowHandle := GetParent(lParam);
  191.       GetClassName(WindowHandle, aClassName, 25);
  192.  
  193.       if (aClassName = 'TEnvDialog') and (DoSubClass) then
  194.       begin
  195.         FlashWindow(Application.MainForm.Handle, False);
  196.         NewWndProcPointer := MakeObjectInstance(PathEdExpert.NewWndProc);
  197.             OrgWndProcPointer := LongInt(SetWindowLong(WindowHandle, gwl_WndProc, LongInt(NewWndProcPointer)));
  198.       end;
  199.       end;
  200.  
  201.     Result := CallNextHookEx(WindowHook, Code, WParam, Lparam);
  202. end;
  203.  
  204. { TPathEdExpert ---------------------------------------------------------------}
  205.  
  206. constructor TPathEdExpert.Create;
  207. var
  208.     Index : integer;
  209.  
  210. begin
  211.   inherited Create;
  212.  
  213.   with ToolServices.GetMainMenu.FindMenuItem('InstallPackagesItem') do
  214.   begin
  215.       Index := GetIndex + 1;
  216.         fMenuItem := GetParent.InsertItem(Index,sMenuText,sMenuName,'',0,0,0,[mfEnabled,mfVisible],MenuClick);
  217.   end;
  218.  
  219.   WindowHook := SetWindowsHookEx(WH_CALLWNDPROC, @Hook, HInstance, GetCurrentThreadID);
  220. end;
  221.  
  222. {------------------------------------------------------------------------------}
  223.  
  224. destructor TPathEdExpert.Destroy;
  225. begin
  226.   MenuItem.Free;
  227.  
  228.   SetWindowLong(WindowHandle, gwl_WndProc, OrgWndProcPointer);
  229.  
  230.     UnHookWindowsHookEx(WindowHook);
  231.   inherited Destroy;
  232. end;
  233.  
  234. {------------------------------------------------------------------------------}
  235.  
  236. procedure TPathEdExpert.MenuClick(Sender:
  237.    TIMenuItemIntf);
  238. begin
  239.   Execute;
  240. end;
  241.  
  242. {------------------------------------------------------------------------------}
  243.  
  244. function TPathEdExpert.GetStyle: TExpertStyle;
  245. begin
  246.   Result := esAddIn;
  247. end;
  248.  
  249. {------------------------------------------------------------------------------}
  250.  
  251. function TPathEdExpert.GetName: string;
  252. begin
  253.   Result := sName;
  254. end;
  255.  
  256. {------------------------------------------------------------------------------}
  257.  
  258. function TPathEdExpert.GetIDString: string;
  259. begin
  260.   Result := 'Solutions Unlimited.PathEditor';
  261. end;
  262.  
  263. {------------------------------------------------------------------------------}
  264.  
  265. procedure TPathEdExpert.Execute;
  266. begin
  267.     with TfrmSetPath.Create(nil) do
  268.   try
  269.         ShowModal;
  270.   finally
  271.     Free;
  272.   end;
  273.  
  274.   UpdateDelphiPath;
  275. end;
  276.  
  277. {------------------------------------------------------------------------------}
  278.  
  279. procedure TPathEdExpert.PreProcessMsg(Sender: TObject;
  280.   var msg: TMessage; var bContinue: Boolean);
  281. begin
  282.      case msg.msg of
  283.     WM_WINDOWPOSCHANGING :
  284.     begin
  285.         TWindowPos(pWindowPos(Msg.Lparam)^).cx := 0;
  286.         TWindowPos(pWindowPos(Msg.Lparam)^).cy := 0;
  287.     end;
  288.   end;
  289. end;
  290.  
  291. {------------------------------------------------------------------------------}
  292.  
  293. procedure TPathEdExpert.PostProcessMsg(Sender: TObject;
  294.   var msg: TMessage; var bContinue: Boolean);
  295. var
  296.     EnvDialog : TCustomForm;
  297.   LibraryTab :  TTabSheet;
  298.  
  299.   PathCombo : TComboBox;
  300.   temp : string;
  301.  
  302. begin
  303.   // Hard coding the Component Names for this release. Will create a wrapper Class
  304.   // for Delphi in the next release.
  305.     case Msg.Msg of
  306.         CM_ACTIVATE:
  307.           if Application.FindComponent('EnvDialog') <> nil then
  308.         begin
  309.             EnvDialog := TForm(Application.FindComponent('EnvDialog'));
  310.           EnvDialog.ModalResult := mrOK;
  311.           PathCombo := TComboBox(EnvDialog.FindComponent('LibOptionsDlg2').FindComponent('ecLibraryPath'));
  312.         PathCombo.Text := Path;
  313.           PostMessage(EnvDialog.Handle, CM_DEACTIVATE, 0, 0);
  314.         end;
  315.         CM_DEACTIVATE:
  316.           if Application.FindComponent('EnvDialog') <> nil then
  317.         begin
  318.           EnvDialog := TForm(Application.FindComponent('EnvDialog'));
  319.           EnvDialog.ModalResult := mrOK;
  320.         end;
  321.     end;
  322. end;
  323.  
  324. procedure TPathEdExpert.UpdateDelphiPath;
  325. var
  326.     ABuilder : TForm;
  327.   EnvDialogItem : TMenuItem;
  328.  
  329. begin
  330.     DoSubClass := True;
  331.   if Assigned(Application.FindComponent('AppBuilder')) then
  332.   begin
  333.       ABuilder := TForm(Application.FindComponent('AppBuilder'));
  334.     if Assigned(ABuilder.FindComponent('ToolsOptionsItem')) then
  335.     begin
  336.           EnvDialogItem := TMenuItem(ABuilder.FindComponent('ToolsOptionsItem'));
  337.             EnvDialogItem.Click;
  338.         DoSubClass := False;
  339.       end;
  340.     end;
  341. end;
  342.  
  343. // These methods are not important for an AddIn expert;
  344. {------------------------------------------------------------------------------}
  345.  
  346. function TPathEdExpert.GetAuthor: string;
  347. begin
  348.     Result := ''
  349. end;
  350.  
  351. {------------------------------------------------------------------------------}
  352.  
  353. function TPathEdExpert.GetComment: string;
  354. begin
  355.     Result := ''
  356. end;
  357.  
  358. {------------------------------------------------------------------------------}
  359.  
  360. function TPathEdExpert.GetGlyph: HICON;
  361. begin
  362.     Result := 0
  363. end;
  364.  
  365. {------------------------------------------------------------------------------}
  366.  
  367. function TPathEdExpert.GetMenuText: string;
  368. begin
  369.     Result := '';
  370. end;
  371.  
  372. {------------------------------------------------------------------------------}
  373.  
  374. function TPathEdExpert.GetPage: string;
  375. begin
  376.     Result := ''
  377. end;
  378.  
  379. {------------------------------------------------------------------------------}
  380.  
  381. function TPathEdExpert.GetState: TExpertState;
  382. begin
  383.     Result := []
  384. end;
  385.  
  386. { TfrmSetPath -----------------------------------------------------------------}
  387.  
  388. procedure TfrmSetPath.SaveList;
  389. var
  390.  i : Integer;
  391.  
  392. begin
  393.     OldList.Clear;
  394.     for i := 0 to lstPath.Items.Count-1 do
  395.       OldList.AddObject(lstPath.Items[i],Pointer(Ord(lstPath.State[i])));
  396. end;
  397.  
  398. {------------------------------------------------------------------------------}
  399.  
  400. procedure TfrmSetPath.RestoreList;
  401. var
  402.  i : Integer;
  403.  
  404. begin
  405.     lstPath.Clear;
  406.     for i := 0 to OldList.Count-1 do
  407.   begin
  408.       lstPath.Items.Add(OldList[i]);
  409.     lstPath.State[i] := TCheckBoxState(OldList.Objects[i]);
  410.   end;
  411. end;
  412.  
  413. {------------------------------------------------------------------------------}
  414.  
  415. function TfrmSetPath.ListSaved : Boolean;
  416. begin
  417.     Result := OldList.Count > 0;
  418. end;
  419.  
  420. {------------------------------------------------------------------------------}
  421.  
  422. procedure TfrmSetPath.ParsePath;
  423. var
  424.     s, x : string;
  425.  
  426. begin
  427.     s := '';
  428.   x := '';
  429.  
  430.   with TRegistry.Create do
  431.   try
  432.       RootKey := HKEY_CURRENT_USER;
  433.     OpenKey(DELPHI_3_PATH, False);
  434.         s := ReadString(DELPHI_3_PATH_KEY);
  435.  
  436.     while s <> '' do
  437.     begin
  438.       lstPath.Items.Add(strToken(s,';'));
  439.       lstPath.State[lstPath.Items.Count-1] := cbChecked
  440.     end;
  441.   finally
  442.       Free;
  443.   end;
  444. end;
  445.  
  446. {------------------------------------------------------------------------------}
  447.  
  448. procedure TfrmSetPath.WritePath;
  449. var
  450.   i : Integer;
  451.   b : string;
  452.  
  453. begin
  454.     Path := '';
  455.  
  456.     for i := 0 to lstPath.Items.Count-1 do
  457.         if lstPath.State[i] = cbChecked then Path := Path + lstPath.Items[i] + ';';
  458.  
  459.     Path := Copy(Path,1,Length(Path)-1);
  460.  
  461.   with TRegistry.Create do
  462.   try
  463.       RootKey := HKEY_CURRENT_USER;
  464.     if not OpenKey(DELPHI_3_PATH,False) then Exit;
  465.     if not ValueExists(DELPHI_3_PATH_KEY) then Exit;
  466.  
  467.        WriteString(DELPHI_3_PATH_KEY, Path);
  468.  
  469.     // Clear out the values. Then Add them in.
  470.        DeleteKey(DELPHI_3_FULLPATH);
  471.        OpenKey(DELPHI_3_FULLPATH, True);
  472.         for i := 0 to lstPath.Items.Count-1 do
  473.     begin
  474.         if lstPath.State[i] = cbChecked
  475.       then b := 'T'
  476.       else b := 'F';
  477.  
  478.         WriteString(IntToStr(i),lstPath.Items[i]+','+b);
  479.     end;
  480.   finally
  481.       Free;
  482.   end;
  483. end;
  484.  
  485. {------------------------------------------------------------------------------}
  486.  
  487. procedure TfrmSetPath.ReadPath;
  488. var
  489.     s : string;
  490.   b: Boolean;
  491.     i : Integer;
  492.   KeyInfo : TRegKeyInfo;
  493.  
  494. begin
  495.     lstPath.Clear;
  496.  
  497.   with TRegistry.Create do
  498.   try
  499.       RootKey := HKEY_CURRENT_USER;
  500.     if not OpenKey(DELPHI_3_FULLPATH,False) then
  501.     begin
  502.         ParsePath;
  503.         Exit;
  504.         end;
  505.  
  506.         GetKeyInfo(KeyInfo);
  507.  
  508.         for i := 0 to KeyInfo.NumValues-1 do
  509.     begin
  510.         s := ReadString(IntToStr(i));
  511.         b := (Copy(s,Pos(',',s)+1,1) = 'T');
  512.         s := Copy(s,1,Pos(',',s)-1);
  513.         lstPath.Items.Add(s);
  514.             if b then lstPath.State[i] := cbChecked;
  515.     end;
  516.   finally
  517.       Free;
  518.   end;
  519. end;
  520.  
  521. {------------------------------------------------------------------------------}
  522.  
  523. procedure TfrmSetPath.SyncWithPackages;
  524. var
  525.   i : Integer;
  526.     s : string;
  527.  
  528. begin
  529.      SaveList;
  530.  
  531.   PackagePath.Clear;
  532.     with TRegistry.Create do
  533.   try
  534.  
  535.       RootKey := HKEY_CURRENT_USER;
  536.     if not OpenKey(DELPHI_3_KNOWN_PACKAGES,False) then Exit;
  537.  
  538.     GetValueNames(PackagePath);
  539.  
  540.     if DisplayPackagePath then
  541.           for i := 0 to PackagePath.Count-1 do
  542.         with PackagePath do
  543.         begin
  544.             s := ExtractFilePath(PackagePath[i]);
  545.           s := Copy(s,1,Length(s)-1);
  546.               if lstPath.Items.IndexOf(s) = -1 then
  547.           begin
  548.               Add(s);
  549.             lstPath.Items.Add(s);
  550.                       lstPath.State[lstPath.Items.Count-1] := cbChecked;
  551.           end;
  552.         end;
  553.   finally
  554.       Free;
  555.   end;
  556. end;
  557.  
  558. {------------------------------------------------------------------------------}
  559.  
  560. procedure TfrmSetPath.AddSubDirs(Sender: TObject);
  561. begin
  562. end;
  563.  
  564. {------------------------------------------------------------------------------}
  565.  
  566. procedure TfrmSetPath.SetDisplayPackagePath(Value : Boolean);
  567. begin
  568.   if FDisplayPackagePath <> Value then
  569.   begin
  570.     FDisplayPackagePath := Value;
  571.   end;
  572. end;
  573.  
  574. {------------------------------------------------------------------------------}
  575.  
  576. procedure TfrmSetPath.SetSyncPackages(Value : Boolean);
  577. begin
  578.   if FSyncPackages <> Value then
  579.   begin
  580.     FSyncPackages := Value;
  581.  
  582.     if FSyncPackages
  583.     then SyncWithPackages
  584.     else
  585.       if ListSaved then RestoreList;
  586.   end;
  587. end;
  588.  
  589. {------------------------------------------------------------------------------}
  590.  
  591. procedure TfrmSetPath.btnAddClick(Sender: TObject);
  592. var
  593.     s : string;
  594.   sl : TStringList;
  595.   i : Integer;
  596.  
  597. begin
  598.   with TBrowseFolder.Create(nil) do
  599.   try
  600.     Title := 'Add Directory to Library Search Path';
  601.     ShowPathInStatusArea := True;
  602.     CustomButtonVisible := True;
  603.     CustomButtonCaption := 'Add Sub Directories';
  604.     CustomButtonType := btCheckBox;
  605.     CustomButtonWidth := 150;
  606.       if Execute then
  607.           with lstPath do
  608.       begin
  609.         if ItemIndex < 0 then ItemIndex := 0;
  610.         // Adding SubDirs?
  611.         if CustomButtonChecked then
  612.         begin
  613.           sl := TStringList.Create;
  614.           sl.Clear;
  615.           try
  616.             ReadDirectoryNames(Directory+'\', sl);
  617.             for i := sl.Count-1 downto 0 do
  618.             begin
  619.               s := Directory+'\'+sl[i];
  620.                 if Items.IndexOf(s) = -1 then Items.Insert(ItemIndex,s);
  621.               State[Items.IndexOf(s)] := cbChecked;
  622.               ItemIndex := Items.IndexOf(s);
  623.             end;
  624.           finally
  625.             sl.Free;
  626.           end;
  627.         end;
  628.  
  629.         s := Directory;
  630.           if Items.IndexOf(s) = -1 then Items.Insert(ItemIndex,s);
  631.         State[Items.IndexOf(s)] := cbChecked;
  632.         ItemIndex := Items.IndexOf(s);
  633.       end;
  634.   finally
  635.     SetFocus;
  636.     Free;
  637.   end;
  638.  
  639.   StatusBar1.SimpleText := 'Path has been updated.';
  640. end;
  641.  
  642. {------------------------------------------------------------------------------}
  643.  
  644. procedure TfrmSetPath.btnRemoveClick(Sender: TObject);
  645. var
  646.   OldIndex : Integer;
  647.  
  648. begin
  649.     with lstPath do
  650.   begin
  651.     OldIndex := ItemIndex;
  652.         if ItemIndex > -1 then Items.Delete(ItemIndex);
  653.  
  654.     Dec(OldIndex);
  655.     if OldIndex < 0 then OldIndex := 0;
  656.     ItemIndex := OldIndex;
  657.   end;
  658.  
  659.   StatusBar1.SimpleText := 'Path has been updated.';
  660. end;
  661.  
  662. {------------------------------------------------------------------------------}
  663.  
  664. procedure TfrmSetPath.btnUpClick(Sender: TObject);
  665. var
  666.     s : string;
  667.  
  668. begin
  669.     with lstPath do
  670.         if ItemIndex > 0 then
  671.     begin
  672.         s := Items[ItemIndex];
  673.         Items.Exchange(ItemIndex, ItemIndex-1);
  674.       ItemIndex := Items.IndexOf(s);
  675.       SetFocus;
  676.     end;
  677. end;
  678.  
  679. {------------------------------------------------------------------------------}
  680.  
  681. procedure TfrmSetPath.btnDownClick(Sender: TObject);
  682. var
  683.     s : string;
  684.  
  685. begin
  686.     with lstPath do
  687.         if ItemIndex < Items.Count-1 then
  688.     begin
  689.         s := Items[ItemIndex];
  690.         Items.Exchange(ItemIndex, ItemIndex+1);
  691.       ItemIndex := Items.IndexOf(s);
  692.       SetFocus;
  693.     end;
  694. end;
  695.  
  696. {------------------------------------------------------------------------------}
  697.  
  698. procedure TfrmSetPath.FormClose(Sender: TObject; var Action: TCloseAction);
  699. begin
  700.     WritePath;
  701.     OldList.Free;
  702.   PackagePath.Free;
  703. end;
  704.  
  705. {------------------------------------------------------------------------------}
  706.  
  707. procedure TfrmSetPath.FormCreate(Sender: TObject);
  708. begin
  709.     OldList := TStringList.Create;
  710.   OldList.Clear;
  711.     ReadPath;
  712.  
  713.   PackagePath := TStringList.Create;
  714. end;
  715.  
  716. {------------------------------------------------------------------------------}
  717.  
  718. procedure TfrmSetPath.FormStorageRestorePlacement(Sender: TObject);
  719. begin
  720.   with TRegistry.Create do
  721.   try
  722.       RootKey := HKEY_CURRENT_USER;
  723.     if not OpenKey(FormStorage.IniFileName+'\'+FormStorage.IniSection,False) then
  724.     begin
  725.         Exit;
  726.         end;
  727.  
  728.     if ValueExists('cbxDisplayPackages_Checked') then
  729.       FDisplayPackagePath := (ReadString('cbxDisplayPackages_Checked') = 'True');
  730.  
  731.     if ValueExists('cbxSync_Checked') then
  732.           SyncPackages := (ReadString('cbxSync_Checked') = 'True');
  733.   finally
  734.     Free;
  735.   end;
  736. end;
  737.  
  738. {------------------------------------------------------------------------------}
  739.  
  740. procedure Register;
  741. begin
  742.     PathEdExpert := TPathEdExpert.Create;
  743.   RegisterLibraryExpert(PathEdExpert);
  744. end;
  745.  
  746. {------------------------------------------------------------------------------}
  747.  
  748. procedure TfrmSetPath.btnOptionsClick(Sender: TObject);
  749. begin
  750.   with TfrmPathOptions.Create(nil) do
  751.   try                          
  752.     if ShowModal = mrOK then
  753.     begin
  754.       DisplayPackagePath  := cbxDisplayPackages.Checked;
  755.       SyncPackages        := cbxSync.Checked;
  756.     end;
  757.   finally
  758.     Free;
  759.   end;
  760. end;
  761.  
  762. {------------------------------------------------------------------------------}
  763.  
  764. procedure TfrmSetPath.Sort1Click(Sender: TObject);
  765. begin
  766.   lstPath.Sorted := True;
  767. end;
  768.  
  769. procedure TfrmSetPath.About1Click(Sender: TObject);
  770. begin
  771.   with TfrmrkAbout.Create(nil) do
  772.   try
  773.     Copyright := '⌐ Copyright 1997 Robert N. Kozak. All Rights Reserved.';
  774.     Version := 'Version 3.02';
  775.     AppName := 'Delphi Library Search Path Editor';
  776.     Title := 'About Delphi Library Search Path Editor';
  777.     SecretMessage := 'You found the Secret Message!';
  778.     ShowModal;
  779.   finally
  780.     Free;
  781.   end;
  782. end;
  783.  
  784. end.
  785.  
  786.